package threadingexercise;


//wait 和 notify()  lambda表达式
public class ThreadingDemo16 {
    public static void main(String[] args) throws InterruptedException {
        //创建一个锁对象
        Object locker = new Object();
        Thread t1 = new Thread(() -> {
            try {
            System.out.println("wait 开始");
            synchronized (locker) {
                    locker.wait();  //锁谁 谁wait  锁的是this 就是 this.wait()
                }
                System.out.println("wait 结束");
            }catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        t1.start();

        Thread.sleep(1000);

        Thread t2 = new Thread(() -> {
            synchronized (locker) {
                System.out.println("notify 开始");
                locker.notify();
                System.out.println("notify 结束");
            }
        });

        t2.start();
    }
}
